//
//  XIVector.m
//  XIEngine
//
//  Created by Balazs Faludi on 08.11.09.
//  Copyright 2009 Universität Basel. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "XIEngine.h"
#include "math.h"

XIFloat
xivlength(const XIVector v)
{
	return sqrtf( xivdot(v, v) );
}

XIFloat
xivlengthsq(const XIVector v)
{
	return xivdot(v, v);
}

XIVector
xivnormalize(const XIVector v)
{
	return xivmult( v, 1.0f/xivlength(v) );
}

XIVector
xivforangle(const XIFloat a)
{
	return xiv(cos(a), sin(a));
}

XIFloat
xivtoangle(const XIVector v)
{
	return atan2(v.y, v.x);
}

XIVector
xivsetangle(XIVector v, XIFloat newAngle)
{
	XIFloat r = xivlength(v);
	return xivpol(r, newAngle);
}

XIVector
xivsetlength(XIVector v, XIFloat newLength)
{
	XIFloat oldLength = xivlength(v);
	XIFloat multiplier = newLength / oldLength;
	return xivmult(v, multiplier);
}

NSString *
xivstr(const XIVector v)
{
	return [NSString stringWithFormat:@"(%f, %f)", v.x, v.y];
}
